home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / UTIL / Alpha 6.5.sit / Tcl / Modes / html.tcl < prev    next >
Text File  |  1996-08-15  |  10KB  |  311 lines

  1. #================================================================================
  2. #
  3. # html.tcl, HTML mode 1.2:  macros and bindings for editing HTML documents.
  4. #
  5. #================================================================================
  6. # version 0.24 (16 July 95) by Scott W. Brim <swb1@cornell.edu>
  7. # version 1.0 -- 1.2 (August 96) by Johan Linde <jl@theophys.kth.se>
  8. #
  9. # See HTML Help in the Help folder.
  10. #
  11. # Original ideas taken from Marc Andreesen's html.el and Tom Scavo's latex.tcl.
  12. #
  13. # If you make improvements to this file, please share them!
  14. #
  15. #                                     Johan Linde <jl@theophys.kth.se>
  16. #
  17. #================================================================================
  18.  
  19. # called by Alpha to load HTML in.  
  20. proc htmlDummy {} {}
  21. proc htmlMenu {} {}
  22.  
  23. #===============================================================================
  24. # Global variables and their management
  25. #===============================================================================
  26.  
  27. if {![info exists htmlMenu]} {set htmlMenu    "・135"}
  28.  
  29. set commentPreString "<!-- "
  30. set commentSufString " -->"
  31.  
  32. # Unsetting old flags and variables which may be defined in arrdefs.tcl 
  33. catch {unset HTMLmodeVars(dlEntries)}
  34. catch {unset HTMLmodeVars(useCtlCmd)}
  35. catch {unset HTMLmodeVars(allContainers)}
  36. catch {unset HTMLmodeVars(quotedAttrs)}
  37. catch {unset HTMLmodeVars(htmlBindPrefix)}
  38. catch {unset HTMLmodeVars(htmlSBindPrefix)}
  39. catch {unset HTMLmodeVars(htmlMenuPrefix)}
  40. catch {unset HTMLmodeVars(htmlSMenuPrefix)}
  41. catch {unset HTMLmodeVars(URLAttrs)}
  42. catch {unset HTMLmodeVars(ColorAttrs)}
  43. catch {unset HTMLmodeVars(elemAttrsForAll)}
  44. catch {unset HTMLmodeVars(useStatusBar)}
  45.  
  46. # Browser
  47. if {![info exists browserSig]} {set browserSig MOSS}
  48. # newModeVar HTML browserSig {MOSS} 0
  49.  
  50. # word breaking and word wrapping
  51. newModeVar HTML wordBreak {¥w+} 0
  52. newModeVar HTML wordBreakPreface {(¥W)} 0
  53. newModeVar HTML wrapBreak {[¥w_]+} 0
  54. newModeVar HTML wrapBreakPreface {([^¥w_])} 0
  55.  
  56.  
  57.  
  58. newModeVar HTML wordWrap        1    1
  59. newModeVar HTML prefixString    $commentPreString    0
  60. newModeVar HTML suffixString    $commentSufString    0
  61.  
  62. # URL to home page.
  63. newModeVar HTML baseURL {} 0
  64. newModeVar HTML basePath {} 0
  65. # Paths to footer files.
  66. newModeVar HTML footers {} 0
  67. # Tag color
  68. newModeVar HTML tagColor        blue 0
  69. # Should elements be lower case?
  70. newModeVar HTML useLowerCase    0    1
  71. # Should ・'s be inserted?
  72. newModeVar HTML    useTabMarks        1    1
  73. # Is <p> a container?
  74. newModeVar HTML pIsContainer    1    1
  75. # Are LI DT and DD containers 
  76. newModeVar HTML lidtAreContainers 0  1
  77. # A list of URLs, cached, to pick from for insertion
  78. newModeVar HTML URLs            {}    0
  79. # A window cache with frames.
  80. newModeVar HTML windows        {}    0
  81. # When browser is launched, should it be brought to front?
  82. newModeVar HTML    browseInForeground    1    1
  83. # list of commonly used character entities
  84. newModeVar HTML defaultCommonChars {"less than" "greater than" "ampersand"} 0
  85. newModeVar HTML commonChars $HTMLmodeVars(defaultCommonChars) 0
  86. # Which HTML package?
  87. newModeVar HTML htmlPackageToUse 1 0
  88. # Include event handlers in attribute dialog?
  89. newModeVar HTML inclEventHandler 0  1
  90. # Beep when asking for attributes in the status bar?
  91. newModeVar HTML promptNoisily    1    1
  92. # Input from big windows?
  93. newModeVar HTML useBigWindows     1    1
  94.  
  95.  
  96. # JavaScript stuff
  97. newModeVar HTML JavaScriptColoring 0 1
  98. newModeVar HTML JavaScriptColor    magenta 0
  99. newModeVar HTML stringColor green 0
  100. newModeVar HTML elecRBrace 0 1
  101. newModeVar HTML elecLBrace 0 1
  102.  
  103. # These mode variables should not appear in the config dialog.
  104.  
  105. set HTMLinvisibleModeVars(htmlPackageToUse) 1
  106. set HTMLinvisibleModeVars(footers) 1
  107. set HTMLinvisibleModeVars(windows) 1
  108. set HTMLinvisibleModeVars(URLs) 1
  109. set HTMLinvisibleModeVars(defaultCommonChars) 1
  110. set HTMLinvisibleModeVars(commonChars) 1
  111. set HTMLinvisibleModeVars(browserSig) 1
  112. set HTMLinvisibleModeVars(baseURL) 1
  113. set HTMLinvisibleModeVars(basePath) 1
  114.  
  115. # These attributes are URLs.
  116. set htmlURLAttr    {HREF= SRC= LOWSRC= ACTION= USEMAP= BACKGROUND= CODEBASE= PLUGINSPAGE=}
  117. # These element attributes are colors
  118. set htmlColorAttr    {BGCOLOR= TEXT= LINK= VLINK= ALINK= COLOR= BORDERCOLOR=}
  119. # These attributes are windows
  120. set htmlWindowAttr {TARGET=}
  121. # Special cases with URLs, colors and windows
  122. set htmlSpecURL {}
  123. set htmlSpecColor {}
  124. set htmlSpecWindow {}
  125. # These elements can be in document HEAD.
  126. set htmlHeadElements1 {BASE ISINDEX LINK META SCRIPT}
  127. set htmlHeadElements3 {BASE ISINDEX LINK META}
  128. # These elements are plug-ins.
  129. set htmlPlugins {EMBED LIVEAUDIO LIVEVIDEO "QUICKTIME MOVIE" "QUICKTIME VR" REALAUDIO}
  130. # HTML mode version
  131. set htmlVersion 1.2
  132.  
  133. #
  134. # Internal Globals
  135. #
  136. set htmlCurSel    ""
  137. set htmlIsSel    0
  138. set htmlExtIsLoaded 0
  139. set html32IsLoaded 0
  140.  
  141. set htmlIsLoaded 1
  142. if { [catch {source "$HOME:Tcl:Modes:htmlEngine.tcl"}] } {
  143.     set htmlIsLoaded 0
  144.     beep
  145.     alertnote "Loading of htmlEngine.tcl failed"
  146. }
  147.  
  148.  
  149. if { [catch {source "$HOME:Tcl:Modes:htmlElems.tcl"}] } {
  150.     set htmlIsLoaded 0
  151.     beep
  152.     alertnote "Loading of htmlElems.tcl failed"
  153. }
  154.  
  155. if { [catch {source "$HOME:Tcl:Modes:htmlMenu.tcl"}] } {
  156.     set htmlIsLoaded 0
  157.     beep
  158.     alertnote "Loading of htmlMenu.tcl failed"
  159. }
  160.  
  161. if {!$HTMLmodeVars(useBigWindows) && [catch {source "$HOME:Tcl:Modes:htmlExtra.tcl"}] } {
  162.     set htmlIsLoaded 0
  163.     beep
  164.     alertnote "Loading of htmExtra.tcl failed"
  165. }
  166.  
  167. #
  168. # Read custom elements
  169. #
  170. # A more advance version of this proc will be needed in future versions of 
  171. # HTML mode, which checks that the custom additions don't conflict with 
  172. # new elements added to HTML mode.
  173. proc htmlReadAdditions {} {
  174.     global PREFS htmlElemAttrRequired1 htmlElemAttrOptional1 htmlElemAttrChoices1
  175.     global htmlElemAttrNumber1 htmlElemEventHandler1 htmlElemKeyBinding htmlElemProc
  176.     global htmlExtIsLoaded htmlURLAttr htmlColorAttr htmlWindowAttr htmlPlugins
  177.     global htmlSpecURL htmlSpecColor htmlSpecWindow
  178.     
  179.     message "Loading custom elementsノ"
  180.     
  181.     htmlExtensions
  182.     set htmlExtIsLoaded 1
  183.     rename htmlExtensions ""
  184.     
  185.     if {![catch {set fid [open $PREFS:HTMLadditions.tcl r]}]} {
  186.         set additions [string trimright [read $fid] "¥n"]
  187.         close $fid
  188.         foreach line [lrange [split $additions "¥n"] 1 end] {
  189.             catch {eval [lindex $line 1]}
  190.         }
  191.     }
  192. }
  193.  
  194.  
  195. #
  196. # Color support
  197. #
  198.  
  199. proc htmlColorizing {} {
  200.      global HTMLmodeVars HTMLwords htmlElemAttrOptional1 htmlElemAttrRequired1
  201.      global htmlExtIsLoaded htmlElemEventHandler1
  202.      
  203.      set HTMLKeyWords {}
  204.     if {[info exists HTMLwords]} {set HTMLKeyWords [concat $HTMLKeyWords $HTMLwords]}
  205.  
  206.     if {$HTMLmodeVars(JavaScriptColoring)} {
  207.         if {!$htmlExtIsLoaded} {
  208.             htmlExtensions
  209.             set htmlExtIsLoaded 1
  210.             rename htmlExtensions ""
  211.         }
  212.         set allHTMLwords [array names htmlElemAttrOptional1]
  213.         foreach elem $allHTMLwords {
  214.             lappend allHTMLkeywords "<${elem}" "/${elem}"
  215.             if {[info exists htmlElemAttrRequired1($elem)]} {
  216.                 foreach attr $htmlElemAttrRequired1($elem) {
  217.                     if {[lsearch -exact $allHTMLkeywords $attr] < 0} {
  218.                         lappend allHTMLkeywords $attr
  219.                     }
  220.                 }
  221.             }    
  222.             foreach attr $htmlElemAttrOptional1($elem) {
  223.                 if {[lsearch -exact $allHTMLkeywords $attr] < 0} {
  224.                     lappend allHTMLkeywords $attr
  225.                 }
  226.             }
  227.         }
  228.         
  229.         lappend allHTMLkeywords "<INPUT"
  230.         set JavaScriptWords {break continue for in function if else new return this var while with true false }
  231.         foreach elem [array names htmlElemEventHandler1] {
  232.             foreach event $htmlElemEventHandler1($elem) {
  233.                 if {[lsearch -exact $JavaScriptWords $event] < 0} {
  234.                     lappend JavaScriptWords $event
  235.                 }
  236.             }
  237.         }
  238.         regModeKeywords -i "<" -i ">"  -I $HTMLmodeVars(tagColor) -e "//" -b "/*" "*/" ¥
  239.         -s $HTMLmodeVars(stringColor) -k $HTMLmodeVars(JavaScriptColor) ¥
  240.         HTML $JavaScriptWords
  241.         regModeKeywords -a -k $HTMLmodeVars(tagColor) ¥
  242.         HTML [concat $HTMLKeyWords $allHTMLkeywords]    
  243.     } else {
  244.         regModeKeywords -b "<" ">" -c $HTMLmodeVars(tagColor) ¥
  245.         -k $HTMLmodeVars(tagColor) HTML $HTMLKeyWords
  246.     }
  247. }
  248.  
  249. # Change color when a color variable is changed.
  250. proc htmlChangeColorizing {name1 name2 op} {
  251.     global HTMLmodeVars
  252.     if {$name2 == "JavaScriptColoring" } {
  253.         htmlColorizing
  254.         message "Coloring may not change until you switch to another window."
  255.     } elseif {$name2 == "tagColor"} {
  256.         if {!$HTMLmodeVars(JavaScriptColoring)} {
  257.             regModeKeywords -a -c $HTMLmodeVars(tagColor) HTML
  258.         } else {
  259.             htmlColorizing
  260.             message "Coloring may not change until you switch to another window."
  261.         }
  262.     } elseif {$name2 == "JavaScriptColor" && $HTMLmodeVars(JavaScriptColoring)} {
  263.         htmlColorizing
  264.         message "Coloring may not change until you switch to another window."
  265.     }
  266.     centerRedraw
  267. }
  268.  
  269. proc htmlShadowAttrUse {name1 name2 op} {
  270.     global HTMLmodeVars htmlMenu
  271.     if {$HTMLmodeVars(useBigWindows)} {
  272.         enableMenuItem $htmlMenu "Use Attributes" off
  273.     } else {
  274.         enableMenuItem $htmlMenu "Use Attributes" on
  275.     }
  276. }
  277.  
  278. trace variable HTMLmodeVars(tagColor) w htmlChangeColorizing
  279. trace variable HTMLmodeVars(JavaScriptColor) w htmlChangeColorizing
  280. trace variable HTMLmodeVars(JavaScriptColoring) w htmlChangeColorizing
  281. trace variable HTMLmodeVars(useBigWindows) w htmlShadowAttrUse
  282.  
  283. if {$htmlIsLoaded} {
  284.     if {[file exists $PREFS:HTMLadditions.tcl]} {catch {htmlReadAdditions} }
  285.     rename htmlReadAdditions ""
  286.     htmlBindKeys
  287.     message "Building HTML menuノ"
  288.     htmlBuildMenu
  289.     htmlColorizing
  290.     message "HTML initialization complete."
  291. } else {
  292.     message "HTML initialization failed."
  293. }
  294.  
  295. unset htmlIsLoaded
  296.  
  297. #===============================================================================
  298. proc parseFuncsHTML {} {
  299.     set pos 0
  300.     while {[set res [search -s -f 1 -r 1 -i 1 -n {name=¥"?¥w+¥"?} $pos]] != ""} {
  301.         set text [getText [car $res] [expr [nextLineStart [cadr $res]] - 1]]
  302.         if {[regexp -nocase {name=¥"?(¥w+)¥"?} $text dummy word]} {
  303.             lappend m $word [lineStart [car $res]]
  304.         }
  305.         set pos [cadr $res]
  306.     }
  307.     return $m
  308. }
  309.  
  310.